package com.zjm.servlet.servlet05_config_context;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ZJM
 * @date 2024/4/12 22:56
 * 像Map一样存储数据
 */
public class ServletContextTest02Servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取ServletContext对象
        ServletContext servletContext = getServletContext();
        servletContext.setAttribute("key1", "value1");
        System.out.println(servletContext.getAttribute("key1"));
    }
}
